package iedcyt.acute.controller.listeners.signComparison;

import iedcyt.acute.model.AuthorFilterCode;
import iedcyt.acute.model.SignComparisonModel;
import iedcyt.acute.view.SignComparisionView;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;

public class SearchAuthorTxtKeyDownListener implements Listener {

	private SignComparisonModel _model;
	private SignComparisionView _view;
	
	public SearchAuthorTxtKeyDownListener(SignComparisionView view, SignComparisonModel model) {
		this._model = model;
		this._view = view;
	}
	
	public void handleEvent(Event event) {

		// Al pulsar 'Intro' se lanza la busqueda de autor
		if (event.character == '\r') {
			_model.setSearch(_view.getSearchText());
			_model.setFilterCode(AuthorFilterCode.FILTER_SEARCH);

			_view.loadAuthors(_model.getAuthors());
			_view.loadSigns1(_model.getAuthorSigns1());
			_view.loadDocuments1(_model.getSign1Docs());
			_view.loadCenters1(_model.getSign1Centers(), _model.isSign1CentersWarning());
			_view.loadCorps1(_model.getSign1Corps(), _model.isSign1CorpsWarning());
			_view.loadSignsCollaborators1(_model.getSign1CollSigns());
			_view.loadAuthorsCollaborators1(_model.getSign1CollAuthors());
			
			_view.loadSigns2(_model.getAuthorSigns2());
			_view.loadDocuments2(_model.getSign2Docs());
			_view.loadCenters2(_model.getSign2Centers(), _model.isSign2CentersWarning());
			_view.loadCorps2(_model.getSign2Corps(), _model.isSign2CorpsWarning());
			_view.loadSignsCollaborators2(_model.getSign2CollSigns());
			_view.loadAuthorsCollaborators2(_model.getSign2CollAuthors());
			
			_view.compareTables();
		}
	}
}
